﻿<UserControl x:Class="Bugger.Presentation.Views.UserBugsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
             xmlns:p="clr-namespace:Bugger.Presentation.Properties"
             xmlns:dd="clr-namespace:Bugger.Presentation.DesignData"
             xmlns:c="clr-namespace:Bugger.Presentation.Converters"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" d:DataContext="{d:DesignInstance dd:SampleUserBugsViewModel, IsDesignTimeCreatable=True}"
             d:DesignHeight="600" d:DesignWidth="400">
    <UserControl.Resources>
        <ResourceDictionary>
            <CollectionViewSource Source="{Binding Bugs}" x:Key="groupedBugs">
                <CollectionViewSource.GroupDescriptions>
                    <PropertyGroupDescription PropertyName="Type"/>
                </CollectionViewSource.GroupDescriptions>
            </CollectionViewSource>
        </ResourceDictionary>
    </UserControl.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="20"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <TextBlock Margin="5,0" Text="{x:Static p:Resources.UserBugs}" VerticalAlignment="Bottom"/>
        <DataGrid ItemsSource="{Binding Mode=OneWay, Source={StaticResource groupedBugs}}" FrozenColumnCount="2" Margin="5" Grid.Row="1" AutoGenerateColumns="False" IsReadOnly="True">
            <DataGrid.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" Width="Auto" HorizontalAlignment="Stretch">
                                <TextBlock Text="Bugs"/>
                            </StackPanel>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <DataGridRowsPresenter/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander>
                                            <Expander.Header>
                                                <StackPanel Orientation="Horizontal">
                                                    <Image HorizontalAlignment="Center" Height="16" Width="16" VerticalAlignment="Center" Source="{Binding Name, Converter={x:Static c:BugTypeToImageConverter.Default}}"/>
                                                    <TextBlock Text="{Binding ItemCount, StringFormat=' Bugs (0)'}"/>
                                                </StackPanel>
                                            </Expander.Header>
                                            <ItemsPresenter />
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </DataGrid.GroupStyle>
            <DataGrid.Columns>
                <DataGridTextColumn Header="{x:Static p:Resources.BugID}" Binding="{Binding ID}" Width="Auto"/>
                <DataGridTextColumn Header="{x:Static p:Resources.BugPriority}" Binding="{Binding Priority}" Width="Auto"/>
                <DataGridTextColumn Header="{x:Static p:Resources.BugSeverity}" Binding="{Binding Severity}" Width="Auto"/>
                <DataGridTextColumn Header="{x:Static p:Resources.BugState}" Binding="{Binding State}" Width="Auto"/>
                <DataGridTextColumn Header="{x:Static p:Resources.BugTitle}" Binding="{Binding Title}" Width="*"/>
            </DataGrid.Columns>
            <DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="2*"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="2*"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{x:Static p:Resources.BugCreatedBy}" FontWeight="Bold"/>
                        <TextBlock Grid.Column="1" Text="{Binding CreatedBy}" Margin="5,0"/>
                        <TextBlock Grid.Column="2" Text="{x:Static p:Resources.BugChangedDate}" FontWeight="Bold"/>
                        <TextBlock Grid.Column="3" Text="{Binding ChangedDate}" Margin="5,0"/>
                        <TextBlock Grid.Row="1" Text="{x:Static p:Resources.BugAssignedTo}" FontWeight="Bold"/>
                        <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding AssignedTo}" Margin="5,0"/>
                        <TextBlock Grid.Row="2" Text="{x:Static p:Resources.BugDescription}" FontWeight="Bold"/>
                        <TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" Text="{Binding Description}" TextWrapping="Wrap" Margin="5,0"/>
                    </Grid>
                </DataTemplate>
            </DataGrid.RowDetailsTemplate>
        </DataGrid>
    </Grid>
</UserControl>
